{%mainunit bitcoin_p2p.pas}

{$IFDEF INTERFACE}
type

  { TMsgInv }

  TMsgInv = class(TMsg)
    Count   : UInt64;
    Vectors : array of TInvVect;
    destructor Destroy; override;
    procedure ParseAndProcess; override;
    class function GetCommand: Tp2pCommand; override;
  end;

{$ENDIF}
{$IFDEF IMPLEMENTATION}

destructor TMsgInv.Destroy;
var
  I : Integer;
begin
  for I := 0 to Count-1 do
    Vectors[i].Free;
  SetLength(Vectors, 0);
  inherited Destroy;
end;

procedure TMsgInv.ParseAndProcess;
var
  Cnt : Integer;
  I   : Integer;
begin
  Cnt := ReadVarInt;
  SetLength(Vectors, cnt);
  for I := 0 to cnt-1 do begin
    Vectors[i] := TInvVect.Create(FPeer, FReceiveData);
    Inc(Count);
    Vectors[i].ParseAndProcess;
  end;

  (*
  {$note remove this logging later}
  for i := 0 to Count-1 do begin
    log('type: %d hash: %s', [Vectors[i].Typ, DigestToHex(Vectors[i].Hash)]);
  end;*)
end;

class function TMsgInv.GetCommand: Tp2pCommand;
begin
  Result := 'inv'#0#0#0#0#0#0#0#0#0;
end;

{$ENDIF}

